﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Mail;
using System.Text;
using System.Web;
using Microsoft.VisualBasic.ApplicationServices;

namespace Pro260Website.Infrastructure.Concrete
{
    public class EmailProcessor
    {
                private readonly EmailSettings _emailSettings;

        public EmailProcessor(EmailSettings settings)
        {
            _emailSettings = settings;
        }
        public void ProcessEmail(string password)
        {
            using(var smtpClient = new SmtpClient())
            {
                smtpClient.EnableSsl = _emailSettings.UseSsl;
                smtpClient.Host = _emailSettings.ServerName;
                smtpClient.Port = _emailSettings.ServerPort;
                smtpClient.UseDefaultCredentials = false;
                smtpClient.Credentials
                = new NetworkCredential(_emailSettings.Username, _emailSettings.Password);
                //if (emailSettings.WriteAsFile)
                //{
                //    smtpClient.DeliveryMethod = SmtpDeliveryMethod.SpecifiedPickupDirectory;
                //    smtpClient.PickupDirectoryLocation = emailSettings.FileLocation;
                //    smtpClient.EnableSsl = false;
               //}
                StringBuilder body = new StringBuilder()
                    .AppendLine("Here is your password:")
                    .AppendLine(password);

                MailMessage mailMessage = new MailMessage(
                _emailSettings.MailFromAddress,
                _emailSettings.MailToAddress, 
                "Password Recovered!", 
                body.ToString());

                smtpClient.Send(mailMessage);
            }
        }
    }

    public class EmailSettings
    {
        public EmailSettings(string email)
        {
            MailToAddress = email;
        }

        public string MailToAddress;
        public string MailFromAddress = "admin@gamersparadise.com";
        public bool UseSsl = true;
        public string Username = "MySmtpUsername";
        public string Password = "MySmtpPassword";
        public string ServerName = "localhost";
        public int ServerPort = 25;
    }
}